import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:ichinesereader/constants.dart';
import 'package:ichinesereader/controller/cache.dart';
import 'package:ichinesereader/exam/placement/PlaceController.dart';
import 'package:ichinesereader/exam/placement/PlacePage.dart';
import 'package:ichinesereader/models/book/BookArguments.dart';
import 'package:ichinesereader/onboard.dart';
import 'package:ichinesereader/pages/book/bookForApp.dart';
import 'package:ichinesereader/pages/book/bookForWeb.dart';
import 'package:ichinesereader/pages/book/bookQuizEditor.dart';
import 'package:ichinesereader/pages/book/bookQuizReviewer.dart';
import 'package:ichinesereader/pages/common/knowledgeWords.dart';
import 'package:ichinesereader/pages/common/myBadges.dart';
import 'package:ichinesereader/pages/common/myWords.dart';
import 'package:ichinesereader/pages/common/report/reportsStudentPersonal.dart';
import 'package:ichinesereader/pages/common/searchbooks.dart';
import 'package:ichinesereader/pages/individual/audiobooks.dart';
import 'package:ichinesereader/pages/individual/individualHome.dart';
import 'package:ichinesereader/pages/individual/myfavorites.dart';
import 'package:ichinesereader/pages/individual/openLibrary.dart';
import 'package:ichinesereader/pages/individual/leveledreadings.dart';
import 'package:ichinesereader/pages/individual/profileSettings.dart';
import 'package:ichinesereader/pages/individual/reports.dart';
import 'package:ichinesereader/pages/individual/subscription.dart';
import 'package:ichinesereader/pages/login/loginReactive.dart';
import 'package:ichinesereader/pages/login/xLogin.dart';
import 'package:ichinesereader/pages/parent/index.dart';
import 'package:ichinesereader/pages/parent/levelReading.dart';
import 'package:ichinesereader/pages/parent/myFavorites.dart';
import 'package:ichinesereader/pages/parent/report.dart';
import 'package:ichinesereader/pages/register/individual/billingForIndividual.dart';
import 'package:ichinesereader/pages/register/individual/languageForIndividual.dart';
import 'package:ichinesereader/pages/register/individual/termForIndividual.dart';
import 'package:ichinesereader/pages/register/individual/userInfo.dart';
import 'package:ichinesereader/pages/schooladmin/bookoverview.dart';
import 'package:ichinesereader/pages/schooladmin/adminClassEditor.dart';
import 'package:ichinesereader/pages/schooladmin/classManagement.dart';
import 'package:ichinesereader/pages/schooladmin/openLibraryReading.dart';
import 'package:ichinesereader/pages/schooladmin/reportsClass.dart';
import 'package:ichinesereader/pages/schooladmin/reports.dart';
import 'package:ichinesereader/pages/schooladmin/reportsStudent.dart';
import 'package:ichinesereader/pages/schooladmin/schooladminhome.dart';
import 'package:ichinesereader/pages/schooladmin/studentsManagement.dart';
import 'package:ichinesereader/pages/schooladmin/teachersManagement.dart';
import 'package:ichinesereader/pages/schooladmin/reportsOverall.dart';
import 'package:ichinesereader/pages/student/announcements.dart';
import 'package:ichinesereader/pages/student/audiobooks.dart';
import 'package:ichinesereader/pages/student/basicWords.dart';
import 'package:ichinesereader/pages/student/booksRecommended.dart';
import 'package:ichinesereader/pages/student/evaluationHome.dart';
import 'package:ichinesereader/pages/student/myFavorites.dart';
import 'package:ichinesereader/pages/student/profileSettings.dart';
import 'package:ichinesereader/pages/student/leveledReading.dart';
import 'package:ichinesereader/pages/student/reports.dart';
import 'package:ichinesereader/pages/teacher/TeacherHome.dart';
import 'package:ichinesereader/pages/teacher/announcementsManagement.dart';
import 'package:ichinesereader/pages/teacher/assessments.dart';
import 'package:ichinesereader/pages/teacher/coreMaterialBooks.dart';
import 'package:ichinesereader/pages/teacher/evaluationHome.dart';
import 'package:ichinesereader/pages/teacher/homework.dart';
import 'package:ichinesereader/pages/teacher/lessonplan.dart';
import 'package:ichinesereader/pages/teacher/openLibraryReading.dart';
import 'package:ichinesereader/pages/teacher/programThemeBooks.dart';
import 'package:ichinesereader/pages/teacher/reports.dart';
import 'package:ichinesereader/pages/teacher/studentsManagement.dart';
import 'package:ichinesereader/pages/teacher/teacherProfile.dart';
import '../pages/schooladmin/adminprofile.dart';
import '../pages/student/studentHome.dart';
import '../pages/student/openLibraryReading.dart';
import '../pages/student/assessment.dart';
import '../pages/student/homework.dart';
import '../pages/common/myRewards.dart';
// import 'package:ichinesereader/pages/teacher/reportsAssessment.dart';
// import 'package:ichinesereader/pages/teacher/reportsBasket.dart';
// import 'package:ichinesereader/pages/teacher/reportsClass.dart';
// import 'package:ichinesereader/pages/teacher/reportsHomework.dart';
// import 'package:ichinesereader/pages/teacher/reportsQuizBook.dart';
// import 'package:ichinesereader/pages/teacher/reportsStudent.dart';
// import 'package:ichinesereader/pages/teacher/reportsSkillBuilding.dart';

class RouteGenerator {
  static Route<dynamic> generateRoute(RouteSettings settings) {
    switch (settings.name) {
      case '/':
        return MaterialPageRoute(
            settings: settings, builder: (_) => LoginReactive());
      case '/login':
        return MaterialPageRoute(
            settings: settings, builder: (_) => LoginReactive());
      case '/xlogin':
        return MaterialPageRoute(settings: settings, builder: (_) => XLogin());
      case '/onboard':
        return MaterialPageRoute(settings: settings, builder: (_) => OnBoard());
      case '/search':
        return MaterialPageRoute(
            settings: settings, builder: (_) => SearchBooksPage());
      case '/placement':
        {
          final bool fromThirdParty =
              settings.arguments == null ? false : settings.arguments as bool;
          Get.lazyPut(() => PlaceController());
          return MaterialPageRoute(
              settings: settings,
              builder: (_) => PlacePage(isFromThirdParty: fromThirdParty));
        }
      case '/common/flashcards':
        return MaterialPageRoute(
            settings: settings, builder: (_) => KnowledgeWordsPage());
      case '/common/mybadges':
        return MaterialPageRoute(
            settings: settings, builder: (_) => MyBadgesPage());
      case '/student/basicCardList':
        return MaterialPageRoute(
            settings: settings, builder: (_) => MyBasicKnowledgeWordsPage());
      case '/common/mywords':
        {
          final args = settings.arguments as List;
          return MaterialPageRoute(
              settings: settings,
              builder: (_) => MyKnowledgeWordsPage(
                    folderId: args[0],
                    level: args[1],
                    isMainFolder: args[2],
                  ));
        }

      case '/student/home':
        return MaterialPageRoute(
            settings: settings, builder: (_) => StudentHome());
      case '/student/books/recommendation':
        return MaterialPageRoute(
            settings: settings, builder: (_) => BooksRecommendBySeriesPage());
      case '/student/library':
        return MaterialPageRoute(
            settings: settings, builder: (_) => BookLibrary());
      case '/student/audiobooks':
        return MaterialPageRoute(
            settings: settings, builder: (_) => StudentAudioBooksPage());
      case '/student/leveledreadings':
        return MaterialPageRoute(
            settings: settings, builder: (_) => LeveledReadings());
      case '/student/myfavorites':
        return MaterialPageRoute(
            settings: settings, builder: (_) => MyFavoritesPageForStudent());
      case '/student/assessments':
        return MaterialPageRoute(
            settings: settings, builder: (_) => MyAssessments());
      case '/student/homework':
        return MaterialPageRoute(
            settings: settings, builder: (_) => MyHomeworkAssignments());
      case '/student/reports':
        return MaterialPageRoute(
            settings: settings, builder: (_) => StudentReportsPage());
      case '/student/book':
        {
          if (GetPlatform.isWeb) {
            final BookArguments args = settings.arguments as BookArguments;
            return MaterialPageRoute(
                settings: settings,
                builder: (_) => BookForWebWebview(
                    bookId: args.bookId,
                    bookCode: args.bookCode,
                    assignmentId: args.assignmentId,
                    readingType: args.readingType,
                    bookTitle: args.bookTitle,
                    userName: args.userName));
          } else {
            final BookArguments args = settings.arguments as BookArguments;
            return MaterialPageRoute(
                settings: settings,
                builder: (_) => InAppWebViewAppBookScreen(
                    bookId: args.bookId,
                    bookCode: args.bookCode,
                    assignmentId: args.assignmentId,
                    readingType: args.readingType,
                    bookTitle: args.bookTitle,
                    userName: args.userName));
          }
        }
      case '/book/quiz':
        {
          final BookArguments args = settings.arguments as BookArguments;
          bool isTeacherOrSchoolAdmin =
              box.get(CacheManagerKey['nanhairole'].toString()) ==
                      Constants.NanhaiRole_Teacher ||
                  box.get(CacheManagerKey['nanhairole'].toString()) ==
                      Constants.NanhaiRole_SchoolAdmin;

          if (isTeacherOrSchoolAdmin) {
            return MaterialPageRoute(
                settings: settings,
                builder: (_) => BookQuizReviewer(
                    bookId: args.bookId, bookTitle: args.bookTitle));
          } else {
            return MaterialPageRoute(
                settings: settings,
                builder: (_) => BookQuizEditor(
                    bookId: args.bookId,
                    bookcode: args.bookCode,
                    bookTitle: args.bookTitle,
                    assignmentId: args.assignmentId));
            // return MaterialPageRoute(
            //             settings: settings,
            //             builder: (_) => InAppWebViewAppBookQuizScreen(
            //                 bookId: args.bookId,
            //                 bookCode: args.bookCode,
            //                 bookTitle: args.bookTitle,
            //                 assignmentId: args.assignmentId,
            //                 readingType: args.readingType));
          }
        }
      case '/student/reward':
        {
          return MaterialPageRoute(
              settings: settings, builder: (_) => InAppWebViewGameScreen());
        }
      case '/student/evaluation':
        return MaterialPageRoute(
            settings: settings, builder: (_) => EvaluationHomepageForStudent());
      case '/student/profile':
        return MaterialPageRoute(
            settings: settings, builder: (_) => StudentProfileSettings());
      case '/student/myannouncements':
        return MaterialPageRoute(
            settings: settings, builder: (_) => StudentMyAnnouncements());
      case '/teacher/home':
        return MaterialPageRoute(
            settings: settings, builder: (_) => TeacherHome());
      case '/teacher/library':
        return MaterialPageRoute(
            settings: settings,
            builder: (_) => OpenReadingBookForTeacherPage());
      case '/teacher/corematerials':
        return MaterialPageRoute(
            settings: settings,
            builder: (_) => CoreMaterialBooksForTeacherPage());
      case '/teacher/themedbooks':
        return MaterialPageRoute(
            settings: settings, builder: (_) => ProgramThemeBooksTeacherPage());
      case '/teacher/students':
        return MaterialPageRoute(
            settings: settings, builder: (_) => StudentsManagement());
      case '/teacher/evaluation':
        return MaterialPageRoute(
            settings: settings, builder: (_) => EvaluationHomepageForTeacher());
      case '/teacher/homework':
        {
          return MaterialPageRoute(
              settings: settings, builder: (_) => HomeworkTeacherPage());
        }
      case '/teacher/lessonplans':
        return MaterialPageRoute(
            settings: settings, builder: (_) => LessonPlansPage());
      case '/teacher/profile':
        return MaterialPageRoute(
            settings: settings, builder: (_) => TeacherProfile());
      case '/teacher/class/announcement':
        return MaterialPageRoute(
            settings: settings, builder: (_) => AnnouncementsManagement());
      case '/teacher/reports':
        {
          return MaterialPageRoute(
              settings: settings, builder: (_) => TeacherReportsHomePage());
        }
      //  case '/teacher/reports/class':
      //   return MaterialPageRoute(
      //       settings: settings, builder: (_) => TeacherReportsClass());
      // case '/teacher/reports/homework':
      //   return MaterialPageRoute(
      //       settings: settings, builder: (_) => TeacherReportsHomework());
      // case '/teacher/reports/student':
      //   return MaterialPageRoute(
      //       settings: settings, builder: (_) => TeacherReportsStudent());
      // case '/teacher/reports/quizBook':
      //   return MaterialPageRoute(
      //       settings: settings, builder: (_) => TeacherReportsQuizBook());
      // case '/teacher/reports/basket':
      //   return MaterialPageRoute(
      //       settings: settings, builder: (_) => TeacherReportsBasket());
      // case '/teacher/reports/assessment':
      //   return MaterialPageRoute(
      //       settings: settings, builder: (_) => TeacherReportsAssessment());
      // case '/teacher/reports/skillBuilding':
      //   return MaterialPageRoute(
      //       settings: settings, builder: (_) => TeacherReportSkillBuilding());
      case '/teacher/assessments':
        {
          return MaterialPageRoute(
              settings: settings, builder: (_) => AssessmentsTeacherPage());
        }
      case '/individual/home':
        return MaterialPageRoute(
            settings: settings, builder: (_) => IndividualHome());
      case '/individual/library':
        return MaterialPageRoute(
            settings: settings, builder: (_) => IndividualOpenLibraryScreen());
      case '/individual/myfavorites':
        return MaterialPageRoute(
            settings: settings, builder: (_) => MyFavoritesPageForIndividual());
      case '/individual/subscription':
        return MaterialPageRoute(
            settings: settings,
            builder: (_) => InAppWebViewIndividualSubscriptionScreen());
      case '/individual/leveledreadings':
        return MaterialPageRoute(
            settings: settings,
            builder: (_) => IndividualLeveledReadingsScreen());
      case '/individual/reports':
        return MaterialPageRoute(
            settings: settings, builder: (_) => IndividualReportsPage());
      case '/individual/audiobooks':
        return MaterialPageRoute(
            settings: settings, builder: (_) => IndividualAudioBooksPage());
      case '/individual/profile':
        return MaterialPageRoute(
            settings: settings, builder: (_) => IndividualProfileSettings());
      case '/schooladmin/home':
        return MaterialPageRoute(
            settings: settings, builder: (_) => SchoolAdminHome());
      case '/schooladmin/bookoverview':
        return MaterialPageRoute(
            settings: settings, builder: (_) => SchoolAdminBookOverview());
      case '/schooladmin/library':
        return MaterialPageRoute(
            settings: settings,
            builder: (_) => OpenReadingBookForSchoolAdminPage());
      case '/schooladmin/profile':
        return MaterialPageRoute(
            settings: settings, builder: (_) => SchoolAdminProfilePage());
      case '/schooladmin/teachers':
        return MaterialPageRoute(
            settings: settings, builder: (_) => TeachersManagement());
      case '/schooladmin/students':
        return MaterialPageRoute(
            settings: settings, builder: (_) => AdminStudentsManagement());
      case '/schooladmin/classes':
        return MaterialPageRoute(
            settings: settings, builder: (_) => ClassesManagement());
      case '/schooladmin/classeditor':
        return MaterialPageRoute(
            settings: settings, builder: (_) => AdminClassEditor());
      case '/schooladmin/reports':
        {
          return MaterialPageRoute(
              settings: settings, builder: (_) => SchoolAdminReports());
        }
      case '/schooladmin/reports/overall':
        return MaterialPageRoute(
            settings: settings, builder: (_) => SchoolAdminReportsOverall());
      case '/schooladmin/reports/class':
        return MaterialPageRoute(
            settings: settings, builder: (_) => SchoolAdminReportsClass());
      case '/schooladmin/reports/student':
        return MaterialPageRoute(
            settings: settings, builder: (_) => SchoolAdminReportsStudent());
      case '/reports/studentPersonal':
        {
          final args = settings.arguments as List;
          return MaterialPageRoute(
              settings: settings,
              builder: (_) => ReportStudentPersonal(
                    classId: args[0],
                    userName: args[1],
                  ));
        }
      case '/parent/home':
        {
          return MaterialPageRoute(
              settings: settings, builder: (_) => ParentHome());
        }
      case '/parent/reports':
        return MaterialPageRoute(
            settings: settings, builder: (_) => ParentReport());
      case '/parent/leveledreadings':
        return MaterialPageRoute(
            settings: settings, builder: (_) => ParentLeveledReadings());
      case '/parent/myfavorites':
        return MaterialPageRoute(
            settings: settings, builder: (_) => MyFavoritesPageForChild());
      case '/account/create/individual':
        return MaterialPageRoute(
            settings: settings, builder: (_) => UserInfoInregister());
      case '/account/create/individual/language':
        return MaterialPageRoute(
            settings: settings, builder: (_) => LanguageForIndividal());
      case '/account/create/individual/condition':
        return MaterialPageRoute(
            settings: settings, builder: (_) => TermForIndividal());
      case '/account/create/individual/billing':
        return MaterialPageRoute(
            settings: settings, builder: (_) => BillingForIndividal());
      case '/error':
        return _errorRoute();
      default:
        return MaterialPageRoute(
            settings: settings, builder: (_) => LoginReactive());
    }
  }

  static Route<dynamic> _errorRoute() {
    return MaterialPageRoute(builder: (_) {
      return Scaffold(
        appBar: AppBar(
          title: Text('Error'),
        ),
        body: Center(
          child: Text('Oops, something wrong ... '),
        ),
      );
    });
  }
}
